<?php 
	$vid = $video_info['Video']['videoid'];
	$feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $vid;
    // read feed into SimpleXML object
    $entry = simplexml_load_file($feedURL);
	$video = parseVideoEntry($entry);
	//http://www.youtube.com/watch?v=Ep4hInYYudc&feature=youtube_gdata_player
	$set_replace = array('http://www.youtube.com/watch?v=','&feature=youtube_gdata_player');
	$link_video = str_replace($set_replace,'',$video->watchURL);
	?>

<div id="show_youtube">
	<div id="main" class="container">
	<div class="main_image">
		<object height="385" width="600" type="application/x-shockwave-flash" data="http://www.youtube.com/v/<?php echo $link_video;?>&amp;hl=en&amp;fs=1&amp;autoplay=0;loop =1;repeat=1" id="player" style="visibility: visible;">
			<param name="allowScriptAccess" value="always"/>
			<param name="allowfullscreen" value="true"/>
		</object>
		<div id="main_image_desc" class="desc">
			<a href="#wrapper" class="collapse">Close Me!</a>
			<div class="block">
				<h2 class="h2_tile_youtube"><a class="a_tile_youtube" href="http://www.youtube.com/v/<?php echo $link_video;?>&amp;hl=en&amp;fs=1&amp;autoplay=0;loop =1;repeat=1"><?php echo $video->title;?></a></h2>
				<span class="attr">- By</span> <span class="view">:&nbsp;<?php
					$authorFeed = simplexml_load_file($video->authorURL); 
					$authorData = $authorFeed->children('http://gdata.youtube.com/schemas/2007');
					echo $video->author;
				?></span>
				<span class="attr">- Thời gian</span> <span class="view">:&nbsp;<?php  echo sprintf("%0.2f", $video->length/60) . " min. ";?> </span>
				<span class="attr"> - Số người xem</span> <span class="view">:&nbsp;<?php echo $video->viewCount;?></span>
				<p><?php  echo $video->description;?></p>
			</div>
		</div>
	</div>
	<div id="fix_right_tab">
				<div id="sidebarTabs_youtube" class="fix_sidebarTabs_youtube">
					<ul id="sidebarTabs_title">
						<li><a rel="sidebarTabs_commented1" class="selected" href="#">Responses</a></li>
						<li><a rel="sidebarTabs_newly_added1" href="#" class="">Related </a></li>
					</ul>

					<div id="sidebarTabs_body1">
						<ol id="sidebarTabs_commented1" style="display: none;">
							<li>
									<div id="research_youtube">
										<ul>
										<!--<?php 
										 /*   if ($video->responsesURL) {
      $responseFeed = simplexml_load_file($video->responsesURL);    
      echo "<tr><td colspan=\"2\"><h3>" . 
      $responseFeed->title . "</h3></td></tr>\n";
      foreach ($responseFeed->entry as $response) {
        $responseVideo = parseVideoEntry($response);
        echo "<tr>\n";
        echo "<td><a href=\"{$responseVideo->watchURL}\">
        <img src=\"$responseVideo->thumbnailURL\"/></a></td>\n";
        echo "<td><a href=\"{$responseVideo->watchURL}\">
        {$responseVideo->title}</a><br/>\n";
        echo sprintf("%0.2f", $responseVideo->length/60) . " min. |
         {$responseVideo->rating} user rating | {$responseVideo->viewCount} 
         views<br/>\n";
        echo $responseVideo->description . "</td>\n";
        echo "</tr>\n";      
      }
    }
									 if ($video->responsesURL) {
											$responseFeed = simplexml_load_file($video->responsesURL); 
											foreach ($responseFeed->entry as $response) {
												$responseVideo = parseVideoEntry($response);
												//http://www.youtube.com/watch?v=ronapR2NnHc&feature=youtube_gdata_player
												$str = '&feature=youtube_gdata_player';
												$replate = '&amp;hl=en&amp;fs=1&amp;autoplay=1;loop =1;repeat=1';
												$watch_video = str_replace($str,$replate,$responseVideo->watchURL,$count);
												$str = 'http://www.youtube.com/watch?v=';
												$replate = 'http://www.youtube.com/v/';
												$watch_video = str_replace($str,$replate,$watch_video,$count);
										 
										?>
											<li>
											<a href="<?php echo $watch_video;?>"><?php echo " <img src=\"$responseVideo->thumbnailURL\"/>";?></a>
											<div class="block">
											<h2><a href="<?php echo $watch_video; ?>"><?php echo $responseVideo->title; ?></a></h2>
											<span class="attr">- Thời gian</span> <span class="view">:&nbsp;<?php echo sprintf("%0.2f", $responseVideo->length/60) . " min."; ?> </span>
											<span class="attr"> - Lượt xem</span> <span class="view">:&nbsp;<?php echo $responseVideo->viewCount; ?></span>
											<p><?php $responseVideo->description;//substr($result['description'],0,200) . "...<p/>\n"; ?></p>
											</div>
											</li>
										<?php }}else{?>
											<li>Chưa có video ở đây</li>
										<?php }?>
										</ul> */?>-->
									</div>
							</li>
								
						</ol>
					
						<ol id="sidebarTabs_newly_added1" style="display: block;">
							<li>
								<div  id="research_youtube_cat">	
									<?php 
										/* if ($video->relatedURL) {
											$relatedFeed = simplexml_load_file($video->relatedURL); 
											foreach ($relatedFeed->entry as $related) {
												$relatedVideo = parseVideoEntry($related);
												//http://www.youtube.com/watch?v=ronapR2NnHc&feature=youtube_gdata_player
												$str = '&feature=youtube_gdata_player';
												$replate = '&amp;hl=en&amp;fs=1&amp;autoplay=1;loop =1;repeat=1';
												$watch_video = str_replace($str,$replate,$relatedVideo->watchURL,$count);
												$str = 'http://www.youtube.com/watch?v=';
												$replate = 'http://www.youtube.com/v/';
												$watch_video = str_replace($str,$replate,$watch_video,$count);
										?>
											<li>
											<a href="<?php echo $watch_video;?>"><?php echo " <img src=\"$responseVideo->thumbnailURL\"/>";?></a>
											<div class="block">
											<h2><a href="<?php echo $watch_video; ?>"><?php echo $relatedVideo->title; ?></a></h2>
											
											<span class="attr">- Thời gian</span> <span class="view">:&nbsp;<?php echo sprintf("%0.2f", $relatedVideo->length/60) . " min."; ?> </span>
											<span class="attr"> - Lượt xem</span> <span class="view">:&nbsp;<?php echo $relatedVideo->viewCount; ?></span>
											<p><?php $relatedVideo->description;//substr($result['description'],0,200) . "...<p/>\n"; ?></p>
											</div>
											</li>
										<?php }}else{*/?>
											<li>Chưa có video ở đây</li>
										<?php// }?>
									
								</div>
							</li>
						</ol>

					</div><!-- /sidebarTabs_body -->
									
					<script type="text/javascript">
					var sidebarTabs_youtube=new ddtabcontent("sidebarTabs_youtube")
					sidebarTabs_youtube.setpersist(true)
					sidebarTabs_youtube.setselectedClassTarget("link")
					sidebarTabs_youtube.init()
					</script>
					<script>
						$(document).ready(function() {	

						//Show Banner
						$(".main_image .desc").show(); //Show Banner
						$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

						//Click and Hover events for thumbnail list
						$(".image_thumb ul li:first").addClass('active'); 
						$(".image_thumb ul li").click(function(){ 
							//Set Variables
							var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
							var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
							var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
							var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
							
							if ($(this).is(".active")) {  //If it's already active, then...
								return false; // Don't click through
							} else {
								//Animate the Teaser				
								$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
									$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
									$(".main_image object").attr({ data: imgTitle , alt: imgAlt});
								});
							}
							
							$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
							$(this).addClass('active');  //add class of 'active' on this list only
							
							return false;
							
						}) .hover(function(){
							$(this).addClass('hover');
							}, function() {
							$(this).removeClass('hover');
						});
						//Toggle Teaser
						$("a.collapse").click(function(){
							$(".main_image .block").slideToggle();
							$("a.collapse").toggleClass("show");
						});
						//$(".main_image .block").slideToggle();
					});//Close Function
					</script>
				</div>
			</div>
		</div>
	</div>
	</div>
</div>
 <?php
    // function to parse a video <entry>
    function parseVideoEntry($entry) {      
      $obj= new stdClass;
      
      // get author name and feed URL
      $obj->author = $entry->author->name;
      $obj->authorURL = $entry->author->uri;
      
      // get nodes in media: namespace for media information
      $media = $entry->children('http://search.yahoo.com/mrss/');
      $obj->title = $media->group->title;
      $obj->description = $media->group->description;
      
      // get video player URL
      $attrs = $media->group->player->attributes();
      $obj->watchURL = $attrs['url']; 
      
      // get video thumbnail
      $attrs = $media->group->thumbnail[0]->attributes();
      $obj->thumbnailURL = $attrs['url']; 
            
      // get <yt:duration> node for video length
      $yt = $media->children('http://gdata.youtube.com/schemas/2007');
      $attrs = $yt->duration->attributes();
      $obj->length = $attrs['seconds']; 
      
      // get <yt:stats> node for viewer statistics
      $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
      $attrs = $yt->statistics->attributes();
      $obj->viewCount = $attrs['viewCount']; 
      
      // get <gd:rating> node for video ratings
      $gd = $entry->children('http://schemas.google.com/g/2005'); 
      if ($gd->rating) { 
        $attrs = $gd->rating->attributes();
        $obj->rating = $attrs['average']; 
      } else {
        $obj->rating = 0;         
      }
        
      // get <gd:comments> node for video comments
      $gd = $entry->children('http://schemas.google.com/g/2005');
      if ($gd->comments->feedLink) { 
        $attrs = $gd->comments->feedLink->attributes();
        $obj->commentsURL = $attrs['href']; 
        $obj->commentsCount = $attrs['countHint']; 
      }
      
      // get feed URL for video responses
      $entry->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom');
      $nodeset = $entry->xpath("feed:link[@rel='http://gdata.youtube.com/schemas/2007#video.responses']"); 
      if (count($nodeset) > 0) {
        $obj->responsesURL = $nodeset[0]['href'];      
      }
         
      // get feed URL for related videos
      $entry->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom');
      $nodeset = $entry->xpath("feed:link[@rel='http://gdata.youtube.com/schemas/2007#video.related']"); 
      if (count($nodeset) > 0) {
        $obj->relatedURL = $nodeset[0]['href'];      
      }
    
      // return object to caller  
      return $obj;      
    } 
?>